package com.yamanyar.weebill.view;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.yamanyar.weebill.domain.Action;
import com.yamanyar.weebill.service.ActionService;

/**
 * Creates an Action.
 * 
 * Created in Jun 28, 2008.
 * 
 * @author Kaan Yamanyar
 */
@Component("createAction")
@Scope("request")
public class CreateAction implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6785907946599065081L;

	private ActionService actionService;

	private Action action = new Action();

	@Autowired
	public CreateAction(ActionService actionService) {
		this.actionService = actionService;
	}

	public Action getAction() {
		return action;
	}

	public void setAction(Action action) {
		this.action = action;
	}

	public String save() {
		actionService.createNew(action);
		FacesMessage facesMessage = new FacesMessage(
				FacesMessage.SEVERITY_INFO, "Action is saved successfully",
				"OK");
		FacesContext.getCurrentInstance().addMessage(null, facesMessage);
		action = new Action();
		return null;
	}
}
